/*
 * TDA8035
 *
 *
 */

#ifndef __TDA8035_H__
#define __TDA8035_H__

#define PIN_EN_5V3V  96
#define PIN_EN_1V8   97
#define PIN_CMDVCCN  98
#define PIN_CLKDIV1
#define PIN_CLKDIV2

#define TDA8035_PIN_CFG() do{gpio_set_output(PIN_EN_5V3V, 0); gpio_set_output(PIN_EN_1V8, 0);\
                             gpio_set_output(PIN_CMDVCCN, 0);}while(0)
#define TDA8035_PIN_5V3V_H() gpio_output(PIN_EN_5V3V, 1)
#define TDA8035_PIN_5V3V_L() gpio_output(PIN_EN_5V3V, 0)
#define TDA8035_PIN_1V8_H()  gpio_output(PIN_EN_1V8, 1)
#define TDA8035_PIN_1V8_L()  gpio_output(PIN_EN_1V8, 0)
#define TDA8035_PIN_CMDVCCN_H() gpio_output(PIN_CMDVCCN, 1)
#define TDA8035_PIN_CMDVCCN_L() gpio_output(PIN_CMDVCCN, 0)
#define TDA8035_PIN_CLKDIV1_H()
#define TDA8035_PIN_CLKDIV1_L()
#define TDA8035_PIN_CLKDIV2_H()
#define TDA8035_PIN_CLKDIV2_L()
#define TDA8035_ENABLE() /* TDA8035 CS High */
#define TDA8035_DISABLE()/* TDA8035 CS Low */

#define TDA8035_ICC_1V8_CFG() do{TDA8035_PIN_1V8_L();}while(0)
#define TDA8035_ICC_3V_CFG()  do{TDA8035_PIN_1V8_H(); TDA8035_PIN_5V3V_L();}while(0)
#define TDA8035_ICC_5V_CFG()  do{TDA8035_PIN_1V8_H(); TDA8035_PIN_5V3V_H();}while(0)

#define TDA8035_CLK_DIV0() do{TDA8035_PIN_CLKDIV1_H(); TDA8035_PIN_CLKDIV2_L();}while(0)
#define TDA8035_CLK_DIV2() do{TDA8035_PIN_CLKDIV1_H(); TDA8035_PIN_CLKDIV2_H();}while(0)
#define TDA8035_CLK_DIV4() do{TDA8035_PIN_CLKDIV1_L(); TDA8035_PIN_CLKDIV2_H();}while(0)
#define TDA8035_CLK_DIV8() do{TDA8035_PIN_CLKDIV1_L(); TDA8035_PIN_CLKDIV2_L();}while(0)

/* Iddp < 3uA @ Deep Shutdown mode, fxtal = stopped */
#define TDA8035_ENTER_DEEP_SHUTDOWN() do{TDA8035_PIN_CMDVCCN_H(); TDA8035_PIN_5V3V_L(); TDA8035_PIN_1V8_L();}while(0)

#define TDA8035_ACTIVE_ICC()   TDA8035_PIN_CMDVCCN_L()
/* Iddp < 500uA @ Shutdown mode, fxtal = stopped */
#define TDA8035_DEACTIVE_ICC() TDA8035_PIN_CMDVCCN_H()


static void tda8035_init(void)
{
    TDA8035_PIN_CFG();
    TDA8035_DEACTIVE_ICC();
    TDA8035_ICC_5V_CFG();
    /* TDA8035 DIV2 decided by hardware */
    TDA8035_ENABLE(); /* it has been enabled by hardware */
}

#endif
